package com.ruoyi.web.wx.controller;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.ruoyi.web.wx.entity.Trash;
import com.ruoyi.web.wx.service.ITrashService;
import com.ruoyi.web.wx.service.ITrashTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 回收垃圾 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-27
 */
@Controller
@RequestMapping("/system/trash")
public class TrashController extends BaseController
{
    private String prefix = "system/trash";
	
	@Autowired
	private ITrashService trashService;
	@Autowired
	private ITrashTypeService trashTypeService;
	@RequiresPermissions("system:trash:view")
	@GetMapping()
	public String trash()
	{
	    return prefix + "/trash";
	}
	
	/**
	 * 查询回收垃圾列表
	 */
	@RequiresPermissions("system:trash:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Trash trash)
	{
		startPage();
        List<Trash> list = trashService.selectTrashList(trash);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出回收垃圾列表
	 */
	@RequiresPermissions("system:trash:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Trash trash)
    {
    	List<Trash> list = trashService.selectTrashList(trash);
        ExcelUtil<Trash> util = new ExcelUtil<Trash>(Trash.class);
        return util.exportExcel(list, "trash");
    }
	
	/**
	 * 新增回收垃圾
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存回收垃圾
	 */
	@RequiresPermissions("system:trash:add")
	@Log(title = "回收垃圾", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Trash trash)
	{trash.setId(UUID.randomUUID().toString().replaceAll("-",""));
		trash.setCreateTime(new Date());
		return toAjax(trashService.insertTrash(trash));
	}

	/**
	 * 修改回收垃圾
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		Trash trash = trashService.selectTrashById(id);
		/*trashTypeService.selectTrashTypeList(new )*/
		mmap.put("trash", trash);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存回收垃圾
	 */
	@RequiresPermissions("system:trash:edit")
	@Log(title = "回收垃圾", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Trash trash)
	{		
		return toAjax(trashService.updateTrash(trash));
	}
	
	/**
	 * 删除回收垃圾
	 */
	@RequiresPermissions("system:trash:remove")
	@Log(title = "回收垃圾", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(trashService.deleteTrashByIds(ids));
	}
	
}
